<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Amaze UI Admin index Examples</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/png" href="__PUBLIC__/assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="__PUBLIC__/assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <link rel="stylesheet" href="__PUBLIC__/assets/css/amazeui.min.css"/>
    <link rel="stylesheet" href="__PUBLIC__/assets/css/admin.css">
    <link rel="stylesheet" href="__PUBLIC__/assets/css/app.css">
</head>

<body data-type="generalComponents">
<include file="./Public/common/htm/header.html"/>


<div class="tpl-page-container tpl-page-header-fixed" id="image_list">

    <include file="./Public/common/htm/menu.html"/>


    <div class="tpl-content-wrapper">
        <div class="tpl-content-page-title">
            微信图片回复设置
        </div>
        <ol class="am-breadcrumb">
            <li><a href="#" class="am-icon-home">首页</a></li>
            <li><a href="#">微信</a></li>
            <li class="am-active"> 微信图片回复设置</li>
        </ol>
        <div class="tpl-portlet-components">
            <div class="portlet-title">
                <div class="caption font-green bold">
                    <span class="am-icon-code"></span> 列表
                </div>


            </div>
            <div class="tpl-block">
                <div class="am-g" style="margin-bottom:  10px;">
                    <div class="am-u-sm-12 am-u-md-6">
                        <div class="am-btn-toolbar">
                            <div class="am-btn-group am-btn-group-xs"><a href="../ImageReply/images_edit">
                                <button type="button" class="am-btn am-btn-default am-btn-success">
                                    <span class="am-icon-plus"></span> 新增
                                </button>
                            </a>
                            </div>
                        </div>
                    </div>
                    <div class="am-u-sm-12 am-u-md-3">
                        <div class="am-input-group am-input-group-sm">
                            <input type="text" class="am-form-field" placeholder="规则查询" name="rule_key_word">
                            <span class="am-input-group-btn">
            <button class="am-btn  am-btn-default am-btn-success tpl-am-btn-success am-icon-search"
                    type="button"
                    @click="search_rules"></button>
          </span>
                        </div>
                    </div>
                </div>
                <div class="am-g">
                    <div class="tpl-table-images">

                        <!--列表渲染-->
                        <div class="am-u-sm-12 am-u-md-6 am-u-lg-4" v-for="image_rule in image_rules">
                            <div class="tpl-table-images-content">
                                <div class="tpl-table-images-content-i-time">发布时间：
                                    {{image_rule.createtime|getFormatTime}}
                                </div>
                                <div class="tpl-i-title">
                                    {{image_rule.rule_name}}
                                </div>
                                <a href="javascript:;" class="tpl-table-images-content-i">
                                    <span class="tpl-table-images-content-i-shadow"></span>
                                    <img :src="'../.'+image_rule.url" alt="" style="height: 220px;">
                                </a>
                                <div class="tpl-table-images-content-block">
                                    <div class="tpl-i-font">
                                        {{image_rule.description}}
                                    </div>
                                    <div class="tpl-i-more">
                                        <ul>
                                        </ul>
                                    </div>
                                    <div class="am-btn-toolbar">
                                        <div class="am-btn-group am-btn-group-xs tpl-edit-content-btn"
                                             style=" padding-left:  0.5%;padding-right:  0.5%;">
                                            <button type="button" class="am-btn am-btn-default am-btn-secondary"
                                                    style="width: 33%!important;"
                                                    :r_id="image_rule.rule_id"
                                                    @click="redirect(image_rule.rule_id)">
                                                <span class="am-icon-edit"></span> 编辑
                                            </button>

                                            <button type="button" class="am-btn am-btn-default am-btn-warning"
                                                    style="width: 33%!important;"
                                                    v-if="image_rule.rule_status == 'ACTIVE'"
                                                    :r_id="image_rule.rule_id"
                                                    :status="image_rule.rule_status"
                                                    @click="change_status">
                                                <span class="am-icon-archive"></span> 禁用
                                            </button>
                                            <button type="button" class="am-btn am-btn-default am-btn-warning"
                                                    style="width: 33%!important; background-color: #228B22" v-else
                                                    :r_id="image_rule.rule_id"
                                                    :status="image_rule.rule_status"
                                                    @click="change_status">
                                                <span class="am-icon-archive"></span> 启用
                                            </button>

                                            <button type="button" class="am-btn am-btn-default am-btn-danger"
                                                    style="width: 33%!important;"
                                                    :r_id="image_rule.id"
                                                    @click="rm_rule">
                                                <span class="am-icon-trash-o"></span> 删除
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!------------>

                        <div class="am-u-lg-12">
                            <div class="am-cf">

                                <div class="am-fr">
                                    <ul class="am-pagination tpl-pagination">

                                        <li @click="pre_page"><a>«</a>
                                        </li>

                                        <!--<li class="am-active"><a href="#">1</a></li>-->
                                        <li v-for="i in max_page" :id="i">
                                            <a v-if="i==current_page" @click="modify_page" :page="i"
                                               style="background-color: #0e90d2">{{i}}</a>
                                            <a v-else @click="modify_page" :page="i">{{i}}</a>
                                        </li>


                                        <li><a @click="next_page">»</a></li>

                                    </ul>
                                </div>
                            </div>
                            <hr>
                        </div>

                    </div>

                </div>
            </div>
            <div class="tpl-alert"></div>
        </div>


    </div>

</div>


<script src="__PUBLIC__/assets/js/jquery.min.js"></script>
<script src="__PUBLIC__/assets/js/amazeui.min.js"></script>
<script src="__PUBLIC__/assets/js/app.js"></script>
<script src="__PUBLIC__/vue.js"></script>

</body>

<script>
    var vm = new Vue({
            el: '#image_list',
            data: {
                current_page: 1,
                max_page: 0,
                image_res: {}
            },
            methods: {
                load_image_list: function (page) {
                    var rule_key_word = document.getElementsByName('rule_key_word');
                    rule_key_word = rule_key_word[0].value;
                    $.ajax({
                        type: 'get',
                        url: '../ImageReplyApi/get_image_reply_list',
                        dataType: 'json',
                        data: {
                            page: page,
                            key_word: rule_key_word,
                        },
                        success: function (data) {
                            if (data.stateCode == 200) {
                                vm.image_res = data.data.rules;
                                vm.max_page = data.data.max_page;
                                vm.current_page = page;
                            }
                        },
                        error: function (data) {
                        }
                    })
                },
                change_status: function (event) {
                    var view = event.target;
                    var rid = view.getAttribute("r_id");
                    var status = view.getAttribute("status");
                    $.ajax({
                        type: 'post',
                        url: '../ImageReplyApi/change_image_reply_status',
                        dataType: 'json',
                        data: {
                            rid: rid,
                            status: status
                        },
                        success: function (data) {
                            if (data.stateCode == 200) {
                                vm.load_image_list(vm.page);
                            }
                        },
                        error: function (data) {
                        }
                    })
                },
                rm_rule: function (event) {
                    var view = event.target;
                    var rid = view.getAttribute("r_id");
                    $.ajax({
                        type: 'get',
                        url: '../ImageReplyApi/remove_rules',
                        dataType: 'json',
                        data: {
                            rid: rid,
                        },
                        success: function (data) {
                            if (data.stateCode == 200) {
                                vm.load_image_list(vm.page);
                            }
                        },
                        error: function (data) {
                        }
                    })
                },
                redirect: function (rid) {
                    window.location = "./images_edit?rid=" + rid;
                },
                search_rules: function (event) {
                    vm.load_image_list(1);
                },
                modify_page: function (event) {
                    var tarView = event.target;
                    var page = tarView.getAttribute('page');
                    this.load_image_list(page);
                },
                pre_page: function (event) {
                    var pre_page = this.current_page - 1;
                    if (pre_page > 0) {
                        this.load_image_list(pre_page);
                    }
                },
                next_page: function (event) {
                    //利用 -0 转化为数字 再进行翻页操作
                    var next_page = this.current_page - 0 + 1;
                    if (next_page <= this.max_page) {
                        this.load_image_list(next_page);
                    }
                },
            },
            filters: {
                //转换时间
                getFormatTime: function (timestamp) {
                    var date = new Date(timestamp * 1000);
                    Y = date.getFullYear() + '-';
                    M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                    D = date.getDate();
                    return Y + M + D;
                },
                formatUrl: function (url) {
                    return '';
                }
            }
        })
        ;

    $(document).ready(function () {
        vm.load_image_list(1);
    });
</script>

</html>